# -*- coding: utf-8 -*-
# created by Alberthch - 陈航  2021/7/15 20:52
# Description:你有一段通过下标访问列表或者元组中元素的代码，但是这样会使得你的代码难以阅读，于是你想通过访问名称来访问元素

from collections import namedtuple

# namedtuple使用
Stock = namedtuple('Stock', ['name', 'shares', 'price'])


def compute_cost(records):
    total = 0.0
    for rec in records:
        # *rec将rec变量解压成多个单变量
        s = Stock(*rec)
        total += s.shares * s.price
    return total


# Some Data
records = [
    ('GOOG', 100, 490.1),
    ('ACME', 100, 123.45),
    ('IBM', 50, 91.15)
]

print(compute_cost(records))
